
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#if HAVE_DIRENT_H
#include <dirent.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if HAVE_MALLOC
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#endif
#if HAVE_NETDB_H
#include <netdb.h>
#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h> /* linux/netfilter_ipv4.h needs defined first */
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SYS_STATVFS_H
#include <sys/statvfs.h>
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#if HAVE_SYSLOG_H
#include <syslog.h>
#endif
#if TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
//#ifdef MTRACE
//#include <mcheck.h>
//#endif /* MTRACE */
//#if HAVE_CLAMAV
//#include <clamav.h>
//#endif

#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <grp.h>
#include <libgen.h>

#ifdef __FreeBSD__
#include <sys/ucred.h>
#include <sys/mount.h>
#include <net/if.h>
#include <net/pfvar.h>
#include <netinet/in_systm.h>
#else
#include <linux/netfilter_ipv4.h>
#endif

#include <netinet/ip.h>
#include <pthread.h>
#include <pwd.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/ioctl.h>

#include "p3scan.h"
#ifdef POP3S
#include "getline_ssl.h"
#endif
#include "parsefile.h"
#include "scanner.h"
#include "restart.h"
#ifdef DEMIME
#include <ripmime/mime.h>
#endif

void bl_noscan_smtp(struct proxycontext *p){ // see if black/whitelist are valid
    struct linebuf *listbuf;
    unsigned long len;
    int blacklist_fd, whitelist_fd, ret;

    if (p->blacklist && strlen(NONULL(p->dspamuser))) {
        do_log(LOG_DEBUG,"Checking blacklist");
        blacklist_fd=r_open2(p->listfileb, O_RDONLY);
        listbuf=linebuf_init(256);
        while ((ret=getlinep3(blacklist_fd, listbuf,NULL))>=0){
        if(strlen(NONULL(listbuf->line))){
            TRIM(listbuf->line);
            if(strstr(p->dspamuser,listbuf->line)){
            p->nosend=1;
            do_log(LOG_DEBUG,"Found %s in %s!", listbuf->line, p->listfileb);
            } // Not in list
        } // Blank line
        }
        linebuf_uninit(listbuf);
        r_close(blacklist_fd);
    }
    if (p->whitelist && !p->nosend && strlen(NONULL(p->dspamuser))) {
        do_log(LOG_DEBUG,"Checking whitelist");
        whitelist_fd=r_open2(p->listfilew, O_RDONLY);
        listbuf=linebuf_init(256);
        while ((ret=getlinep3(whitelist_fd, listbuf,NULL))>=0){
        if(strlen(NONULL(listbuf->line))){
            TRIM(listbuf->line);
            if(strstr(p->dspamuser,listbuf->line)){
            p->noscan=1;
            do_log(LOG_DEBUG,"Found %s in %s.", listbuf->line, p->listfilew);
            }
        }
        }
        linebuf_uninit(listbuf);
        r_close(whitelist_fd);
    }

}